local skel = fk.CreateSkill{
  name = "diy_ready_skill&",
}

Fk:loadTranslationTable{
  ["diy_ready_skill&"] = "蓄势技",
  [":diy_ready_skill&"] = "出牌阶段，你可以弃置三张牌，重置一个本轮未发动过的蓄势技。",
  ["#diy_ready_skill&"] = "你可以弃置三张牌，重置一个本轮未发动过的蓄势技",
}

---@class DIYUtility
local DIY = require "packages/diy_utility/_base"

skel:addEffect("active", {
  prompt = "#diy_ready_skill&",
  anim_type = "special",
  --card_num = 3,
  target_num = 0,
  interaction = function (self, player)
    local skills = {}
    for _, s in ipairs(player:getAllSkills()) do
      if DIY.isReadying(player, s) and player:usedSkillTimes(s.name, Player.HistoryRound) == 0 then
        table.insert(skills, s.name)
      end
    end
    return UI.ComboBox { choices = skills }
  end,
  can_use = function(self, player)
    return table.find(player:getAllSkills(), function(s)
      return DIY.isReadying(player, s) and player:usedSkillTimes(s.name, Player.HistoryRound) == 0
    end)
  end,
  card_filter = function (self, player, to_select, selected)
    if player:prohibitDiscard(to_select) then return false end
    local skill = self.interaction.data
    return skill and #selected < 3 -- getReadySkillCardNum(player, skill) 
    --- TODO: 修改蓄势需要弃牌数，以后再说哈
  end,
  feasible = function (self, player, selected, selected_cards, card)
    local skill = self.interaction.data
    return skill and #selected_cards == 3 -- getReadySkillCardNum(player, skill)
  end,
  on_use = function(self, room, effect)
    local skill_name = self.interaction.data
    if not skill_name then return end
    local player = effect.from
    room:throwCard(effect.cards, self.name, player, player)
    if not player.dead then
      room:removeTableMark(player, "@diy_skill_readying", skill_name)
      local skill = Fk.skills[skill_name]
      room.logic:trigger(DIY.SkillReadyFinish, player, {
        who = player, skill = skill, reason = "discard"
      })
    end
  end,
})

skel:addEffect("invalidity", {
  invalidity_func = function (self, player, skill)
    return skill:hasTag(DIY.ReadySkill) and DIY.isReadying(player, skill)
  end,
})

return skel
